package net.oschina.archx.service;

import net.oschina.archx.dao.TestDao;
import net.oschina.archx.dao.TransDao;
import net.oschina.archx.entiry.TestModel;
import net.oschina.archx.spring.sequoiadb.annotation.SequoiaTransaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
 * TestService
 *
 * @author Archx
 * @date 2015/6/30 0030
 */
@Service
public class TestService {

    @Autowired
    private TestDao tsd;

    @Autowired
    private TransDao trd;

    @SequoiaTransaction(rollbackFor = {RuntimeException.class})
    public void insert(TestModel tm) {
        tsd.insert(tm);
    }

    public void delete(Serializable id) {
        tsd.delete(id);
    }

    @SequoiaTransaction(rollbackFor = {RuntimeException.class})
    public void trans(TestModel tm) {
        tsd.insert(tm);
        System.out.println("......");
        trd.delete(tm.getId());
        throw new RuntimeException("事务测试....");
    }
}
